structure Main = 
struct

(* These are MAGIC! I just COPY from ml-yacc manual *)
structure CLrVals = CLrValsFun(structure Token = LrParser.Token)

structure CLex = CLexFun(structure Tokens = CLrVals.Tokens)

structure CParser = Join( structure LrParser = LrParser
                          structure ParserData = CLrVals.ParserData
			  structure Lex = CLex)


open Ast

fun parse_stream stream = 
    let val lexer = CParser.makeLexer 
                        (fn i => TextIO.inputN(stream,i))
        val (ast,_) = CParser.parse(0,lexer,fn (_,_,_) => print "error\n",())
    in
        ast
    end

fun parse_file f = 
    let val s = TextIO.openIn f
        val r = parse_stream s
	val str = Ast.Program2Str r
    in
        r before TextIO.closeIn s
    end

fun parse_string s = Ast.Program2Str (parse_stream (TextIO.openString s))
                     
end 
